package com.ss.android.newmedia.feedback;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.Environment;
import android.os.Message;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;

import com.bytedance.article.common.c.TTUtils;
import com.bytedance.common.utility.UIUtils;
import com.bytedance.common.utility.c.SharedPreferenceCompat;
import com.bytedance.common.utility.collection.WeakHandler;
import com.bytedance.common.utility.collection.WeakHandler.Callback;
import com.bytedance.frameworks.b.a.ComponentsManifest;
import com.ss.android.article.browser.R;
import com.ss.android.cc;
import com.ss.android.common.util.ToolUtils;
import com.ss.android.newmedia.activity.FragmentActivity;

import java.io.File;
import java.lang.ref.WeakReference;

public class SubmitFeedbackActivity extends FragmentActivity implements Callback {
    EditText a;
    EditText b;
    ProgressDialog c;
    String d;
    String e;
    WeakHandler f;
    InputMethodManager g;
    String h;
    String i;
    String j;
    boolean k;
    private ImageView l;
    private WeakReference m;

    public SubmitFeedbackActivity() {

        this.f = new WeakHandler(((Callback) this));
        this.k = false;
    }

    final void a() {
        if (this.m != null) {
            Object v0 = this.m.get();
            if (v0 != null) {
                ((j) v0).b = true;
                if (((j) v0).a == null) {
                } else {
                    int v1;
                    for (v1 = 0; v1 < ((j) v0).a.length; ++v1) {
                        if (((j) v0).a[v1] != null) {
                            try {
                                com.bytedance.frameworks.baselib.network.http.parser.a v2_1 = ((j) v0).a[v1];
                                if (v2_1.a == null) {
                                    continue;
                                }

                                if (v2_1.a.isCanceled()) {
                                    continue;
                                }

                                v2_1.a.cancel();
                            } catch (Throwable v2) {
                            }
                        }
                    }
                }
            }
            this.m.clear();
            this.m = null;
        }
    }

    final void a(m arg3) {
        j v0 = new j(this.f, ((Context) this), arg3);
        v0.start();
        if (this.m != null) {
            this.m.clear();
            this.m = null;
        }

        this.m = new WeakReference(v0);
    }

    public int getDayBackgroundRes() {
        return R.color.vp;
    }

    public int getLayout() {
        return R.layout.submit_feedback_activity;
    }

    public void handleMsg(Message message) {
        int v2 = R.drawable.doneicon_popup_textpage;
        if (this.isViewValid()) {
            if (message.what != 10007) {
                this.k = false;
                if (this.c != null) {
                    this.c.dismiss();
                    this.c = null;
                }

                if (message.what == 10) {
                    UIUtils.showImageToast(((Context) this), v2, R.string.toast_send_success);
                    this.setResult(-1);
                    this.finish();
                    return;
                }

                UIUtils.showImageToast(((Context) this), v2, this.getString(TTUtils.a(message.arg1)));
            } else if ((message.obj instanceof m)) {
                this.a((com.ss.android.newmedia.feedback.m) message.obj);
            }
        }
    }

    public void init() {
        super.init();
        Intent v0 = this.getIntent();
        if (v0 != null) {
            this.d = v0.getStringExtra("key_appkey");
        }

        if (this.d == null) {
            this.d = "";
        }

        TTUtils.getNightModeColorFilter();
        this.g = (InputMethodManager) this.getSystemService(INPUT_METHOD_SERVICE);
        this.h = Environment.getExternalStorageDirectory().getPath() + "/Android/data/" + this.getPackageName() + "/cache/feedback";
        this.j = "camera.data";
        this.i = "upload.data";
        this.mTitleView.setText(com.ss.android.article.browser.R.string.title_feedback);
        this.mRightBtn.setText(com.ss.android.article.browser.R.string.label_send);
        this.mRightBtn.setVisibility(View.VISIBLE);
        this.mRightBtn.setOnClickListener(new p(this));
        this.l = (ImageView) this.findViewById(R.id.image_btn);
        this.l.setOnClickListener(new q(this));
        this.a = (EditText) this.findViewById(R.id.content);
        this.b = (EditText) this.findViewById(R.id.contact);
        this.findViewById(com.ss.android.article.browser.R.id.content_layout);
        this.findViewById(com.ss.android.article.browser.R.id.contact_tip);
        this.b.setText(com.ss.android.newmedia.feedback.a.a().a);
    }

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        int v1;
        Bitmap v0_1;
        Bitmap.Config v5 = null;
        int v4 = R.string.photo_error_no_photo;
        int v3 = R.drawable.close_popup_textpage;
        int v2 = 50;
        if (requestCode != 1003) {
            if (requestCode == 1002) {
                if (resultCode == 0) {
                    return;
                }

                this.e = this.h + "/" + this.j;
                v0_1 = android.support.design.a.decodeFile(this.e, v2, v2, v5);
                v1 = android.support.design.a.e(this.e);
                if (v1 != 0) {
                    v0_1 = android.support.design.a.a(v0_1, v1);
                }

                if (v0_1 != null) {
                    this.l.setImageBitmap(v0_1);
                    com.ss.android.j.b.isNightModeToggled();
                    return;
                }

                this.e = "";
                return;
            }

            super.onActivityResult(requestCode, resultCode, intent);
        } else if (resultCode != 0 && intent != null) {
            String v0 = TTUtils.a(((Context) this), intent.getData());
            if (android.support.design.a.isTextEmpty(v0)) {
                UIUtils.showImageToast(((Context) this), v3, v4);
            } else if (!new File(v0).exists()) {
                UIUtils.showImageToast(((Context) this), v3, v4);
            } else {
                this.e = v0;
                v0_1 = android.support.design.a.decodeFile(this.e, v2, v2, v5);
                v1 = android.support.design.a.e(this.e);
                if (v1 != 0) {
                    v0_1 = android.support.design.a.a(v0_1, v1);
                }

                if (v0_1 != null) {
                    this.l.setImageBitmap(v0_1);
                    com.ss.android.j.b.isNightModeToggled();
                    return;
                }

                this.e = "";
            }
        }
    }

    public void onBackPressed() {
        if (!this.isFinishing()) {
            Intent v0 = null;
            if (this.isTaskRoot()) {
                v0 = ToolUtils.getLaunchIntentForPackage(((Context) this), this.getPackageName());
            }

            if (v0 != null) {
                this.finish();
                this.startActivity(v0);
                return;
            }

            this.setResult(0);
            this.finish();
        }
    }

    public void onPause() {
        if (this.c != null) {
            this.c.dismiss();
            this.c = null;
        }

        super.onPause();
        if (this.b != null) {
            com.ss.android.newmedia.feedback.a v1 = com.ss.android.newmedia.feedback.a.a();
            v1.a = this.b.getText().toString();
            Object v0 = ComponentsManifest.findComponent(cc.class);
            if (v0 != null) {
                SharedPreferences.Editor v0_1 = ((cc) v0).getAppSettingSp().edit();
                v0_1.putString("contact_info", v1.a);
                SharedPreferenceCompat.commit(v0_1);
            }
        }

        this.a();
        this.k = false;
    }

    public void onPostResume() {
        super.onPostResume();
        this.b.postDelayed(new com.ss.android.newmedia.feedback.r(this), 200);
    }
}

